package com.charm.watercress.adapter

import android.widget.ImageView
import android.widget.RatingBar
import android.widget.TextView
import com.chad.library.adapter.base.BaseViewHolder
import com.charm.codes.imageLoad.XGlide
import com.charm.frameworkarou.recycleadapter.QuickRecyAdapter
import com.charm.watercress.R
import com.charm.watercress.entity.FilmEntity

/**
 * Created by tools on 2018/1/11.
 */
class FilmAdapter(list: List<FilmEntity>?) : QuickRecyAdapter<FilmEntity>(list) {
    override fun convert(helper: BaseViewHolder?, item: FilmEntity?) {
        helper!!.getView<TextView>(R.id.title).text = item!!.title
        var image = helper!!.getView<ImageView>(R.id.image)
        if (item.imageUrls != null) {
            if (item.imageUrls[0] != null) {
                XGlide.getInstance().with(mContext)
                        .load(item.imageUrls[0])
                        .placeholder(R.drawable.bg_block)
                        .error(R.drawable.bg_block)
                        .into(image)
                        .displayImage()
            }
        }
        helper.addOnClickListener(R.id.image)
        helper!!.getView<RatingBar>(R.id.rating).rating = item.rating.toFloat()
    }

    override fun getLayoutResId(): Int {
        return R.layout.item_film
    }

}